package com.aaa.phone.service.lovecarrecycleservice.impl;

import com.aaa.phone.dao.lovecarrecycledao.LoveCarRecycleDao;
import com.aaa.phone.service.lovecarrecycleservice.LoveCarRecycleService;
import com.aaa.phone.systemconst.ISystemConst;
import com.aaa.web.commons.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description:手机爱车回收业务实现层
* @author: 王林林
* @create: 2018/12/17 10:19
**/
@Service
public class LoveCarRecycleServiceImpl implements LoveCarRecycleService {

    @Autowired
    private LoveCarRecycleDao dao;

    /**
     * 获取所有车型
     * @return
     */
    @Override
    public List<Map> getType() {
        return dao.getType();
    }

    /**
     * 根据手机号获取当前账户所有车辆出厂号
     * @param telephone
     * @return
     */
    @Override
    public List<Map> getCarCode(String telephone) {
        Map<String, Object> map = new HashMap<>();
        map.put("telephone",telephone);
        return dao.getCarCode(map);
    }

    /**
     * 添加车辆回收信息
     * @param carcode
     * @param telephone
     * @return
     */
    @Override
    public Result addRecycleInfo(String carcode, String telephone) {
        Map<String, Object> map = new HashMap<>();
        map.put("telephone",telephone);
        map.put("carcode",carcode);
        int i=ISystemConst.ZERO;
        Result result = new Result();
        try {
             i = dao.addRecycleInfo(map);
        }catch (Exception e){
            result.setCode(ISystemConst.PHONE_DEFEAT_CODE);
            return result;
        }

        //判断数据库是否添加数据
        if (i>ISystemConst.ZERO){
            //数据库添加成功返回成功状态码200
            result.setCode(ISystemConst.PHONE_SUCCESS_CODE);
            return result;
        }else {
            //数据库添加失败返回失败状态码400
            result.setCode(ISystemConst.PHONE_DEFEAT_CODE);
            return result;
        }
    }


}
